//
//  income_B2.m
//  K-Music
//
//  Created by CHUN on 16/1/15.
//  Copyright © 2016年 CHUN. All rights reserved.
//

#import "income_B2.h"
#import "CustomSearch.h"

@interface income_B2 ()<UITableViewDataSource ,UITableViewDelegate>

@end

@implementation income_B2

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = RGB(241, 241, 241);
    self.navigationItem.title = @"我的收入";

    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithIcon:@"back" highIcon:@"back" target:self action:@selector(back_back)];
    
    [self creatUI];
}
- (void)back_back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -creatUI-
- (void)creatUI
{
    UITableView * income_B2_TableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    income_B2_TableView.delegate = self;
    income_B2_TableView.dataSource =self;
    income_B2_TableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    income_B2_TableView.backgroundColor = RGB(241, 241, 241);
    [self.view addSubview:income_B2_TableView];
    
}

#pragma mark -UITableViewDataSource-

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1) {
        return 80;
    }
    if (indexPath.section == 2) {
        return 50;
    }
    return 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"cellID";
    UITableViewCell * coinsCell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (coinsCell == nil) {
        coinsCell  = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    coinsCell.backgroundColor = [UIColor clearColor];
    coinsCell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if (indexPath.section == 0) {
        
        UIImageView * bg = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"preson_b"]];
        bg.frame = CGRectMake(0, 0, WIDTH, 100);
        
        [coinsCell.contentView addSubview:bg];
//        coinsCell.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"preson_b"]];
        
        UILabel * coinsNumber = [[UILabel alloc] init];
        coinsNumber.text = [NSString stringWithFormat:@"%@",[FileStorage NSUserDefault_getObjectForKey:user_income]];
        
        coinsNumber.font = [UIFont systemFontOfSize:30];
        coinsNumber.textColor = RGB(234, 149, 67);
        [coinsCell.contentView addSubview:coinsNumber];
        
        UILabel * coinsType = [[UILabel alloc] init];
        coinsType.text = @"金币";
        coinsType.font = [UIFont systemFontOfSize:15];
        coinsType.textColor = [UIColor whiteColor];
        [coinsCell.contentView addSubview:coinsType];
        
        [coinsNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(coinsCell.contentView);
            make.centerY.equalTo(coinsCell.contentView);
        }];
        
        [coinsType mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsNumber.mas_right).with.offset(10);
            make.centerY.equalTo(coinsCell.contentView);
        }];
        
        
    }
    if (indexPath.section == 1) {
        
        UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 30)];
        title.text = @"金额（元）  |";
        
        CustomSearch * search = [[CustomSearch alloc] init];
        search.backgroundColor = [UIColor whiteColor];
        [search CustomSearchLeftImage:title RightImage:nil ShowString:@"输入需要充值的金币整数" FontSize:15 ClearBtn:YES];
        [coinsCell.contentView addSubview:search];
        
        [search mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsCell.contentView.mas_left);
            make.right.equalTo(coinsCell.contentView.mas_right);
            make.height.mas_equalTo(@50);
            make.centerY.equalTo(coinsCell.contentView);
        }];
    }
    if (indexPath.section == 2) {
        UILabel * payLabel = [[UILabel alloc] init];
        payLabel.font = [UIFont systemFontOfSize:15];
        payLabel.numberOfLines = 0;
        payLabel.text = @"*备注: 1000个金币 = 1元";
        payLabel.textColor = RGB(234, 149, 67);
        [coinsCell.contentView addSubview:payLabel];
        
        [payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsCell.contentView.mas_left).with.offset(10);
            make.right.equalTo(coinsCell.contentView.mas_right).with.offset(-10);
        }];
    }
    if (indexPath.section == 3) {
        UIButton * payButton = [[UIButton alloc] init];
        [payButton setTitle:@"提取" forState:UIControlStateNormal];
        [payButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        payButton.backgroundColor = RGB(234, 149, 67);
        [coinsCell.contentView addSubview:payButton];
        
        [payButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(coinsCell.contentView.mas_left).with.offset(15);
            make.right.equalTo(coinsCell.contentView.mas_right).with.offset(-15);
            make.height.mas_equalTo(@44);
        }];
    }
    return coinsCell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:tableView.indexPathForSelectedRow animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
